// 定义车辆接口
interface XCar {
    plateNumber: string;
    name: string;
    calculatePrice(distance: number): number;
}

// 实现快车类
class ExpressCar implements XCar {
    plateNumber: string;
    name: string;

    constructor(plateNumber: string, name: string) {
        this.plateNumber = plateNumber;
        this.name = name;
    }

    calculatePrice(distance: number): number {
        return distance; // 快车每公里1元
    }
}

// 实现专车类
class SpecialCar implements XCar {
    plateNumber: string;
    name: string;

    constructor(plateNumber: string, name: string) {
        this.plateNumber = plateNumber;
        this.name = name;
    }

    calculatePrice(distance: number): number {
        return distance * 2; // 专车每公里2元
    }
}

// 行程类
class Trip {
    private car:XCar
    constructor( car:XCar) {
        this.car = car
    }

    start(): void {
        console.log(`开始行程，车辆信息：${this.car.name} - ${this.car.plateNumber}`);
    }

    end( distance: number): void {
        const price = this.car.calculatePrice(distance);
        console.log(`行程结束，费用为 ${price} 元`);
    }
}

// 使用示例
const expressCar = new ExpressCar('京A12345', '快车');
const specialCar = new SpecialCar('京B67890', '专车');
const trip = new Trip(expressCar);

trip.start();
trip.end( 5); // 假定行程为5公里，输出：行程结束，费用为 5 元
const trip2 = new Trip(specialCar);
trip2.start();
trip2.end( 5); // 假定行程为5公里，输出：行程结束，费用为 10 元
